﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO;


using System.Threading;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;
using System.IO.Ports;
using CCWin;
namespace weiqijiance
{
    public partial class LUGpeizhi : CCSkinMain
    {
       public string[] sname;
       public string[] snamecolor;
       public string name;

       public string[] sBJname;
       public string[] sBJnamecolor;
       public string BJname;
       // /声明INI文件的写操作函数 WritePrivateProfileString()
       [DllImport("kernel32")]
       private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

       //声明INI文件的读操作函数 GetPrivateProfileString()
       [DllImport("kernel32")]
       private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
       private string sPath = null;

        public LUGpeizhi()
        {
            InitializeComponent();
            sname = new string[4] {"提示框",
                                    "号牌号码",
                                    "功率",
                                    "转速"};
            snamecolor = new string[4] {"#AABBCC",
                                    "#AABBCC",
                                    "#AABBCC",
                                    "#AABBCC"};

            sBJname = new string[1] {"曲线控件"};
            sBJnamecolor = new string[1] {"#AABBCC"};

            readshezhi();
            list();

            readshezhiBJ();
            listBJ();
        }
        //ini文件
        public void Ini(string path)
        {
            this.sPath = path;
        }
        public void Writue(string section, string key, string value)
        {
            // section=配置节，key=键名，value=键值，path=路径
            WritePrivateProfileString(section, key, value, sPath);
        }
        public string ReadValue(string section, string key)
        {
            // 每次从ini中读取多少字节
            System.Text.StringBuilder temp = new System.Text.StringBuilder(255);

            // section=配置节，key=键名，temp=上面，path=路径
            GetPrivateProfileString(section, key, "", temp, 255, sPath);
            return temp.ToString();
        }
        //ini文件
        private void button1_Click(object sender, EventArgs e)
        {
            

         
        }
        public void list()
        {
            //  String color = System.Drawing.ColorTranslator.ToHtml(colorEdit1.Color); //将Color对象转为String对象。如#AABBCC这种
            //  colorEdit1.Color = System.Drawing.ColorTranslator.FromHtml(color);//将#AABBCC这种字符串对象转为Color对象。
            listView1.Items.Clear();
            for (int i = 0; i < 4; i++)
            {

                ListViewItem li = new ListViewItem();
                li.SubItems[0].Text = sname[i];
                li.SubItems.Add(snamecolor[i]);
                li.ForeColor = System.Drawing.ColorTranslator.FromHtml(snamecolor[i]);//字体颜色
                listView1.Items.Add(li);
               
            }

        }
        public void listBJ()
        {
            listView2.Items.Clear();
            for (int i = 0; i < 1; i++)
            {

                ListViewItem li = new ListViewItem();
                li.SubItems[0].Text = sBJname[i];
                li.SubItems.Add(sBJnamecolor[i]);
                li.ForeColor = System.Drawing.ColorTranslator.FromHtml(sBJnamecolor[i]);//字体颜色
                listView2.Items.Add(li);

            }

        }
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listView1.SelectedItems)
            {
                name = item.SubItems[0].Text.ToString().Trim();
               
            }
        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            this.colorDialog1.ShowDialog();
           // this.BackColor = this.colorDialog1.Color;
            String color = System.Drawing.ColorTranslator.ToHtml(this.colorDialog1.Color);
            baocunshezhi(name, color);
            readshezhi();
            list();
        }

        public void baocunshezhi(string name,string namecolor)
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\加载减速颜色配置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            Writue("加载减速颜色配置", name, namecolor);
        }
        public void baocunshezhiBJ(string name, string namecolor)
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\加载减速颜色配置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            Writue("加载减速颜色配置", name, namecolor);
        }

        public void readshezhi()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\加载减速颜色配置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            for (int i = 0; i < 4; i++)
            {
                snamecolor[i] = ReadValue("加载减速颜色配置", sname[i]);
            }
        }
        public void readshezhiBJ()
        {
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\加载减速颜色配置.ini";
            string path1 = string.Format(@"{0}", path);
            Ini(path1);

            for (int i = 0; i < 1; i++)
            {
                sBJnamecolor[i] = ReadValue("加载减速颜色配置", sBJname[i]);
            }
        }
        private void listView2_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listView2.SelectedItems)
            {
                BJname = item.SubItems[0].Text.ToString().Trim();

            }
        }

        private void listView2_DoubleClick(object sender, EventArgs e)
        {
            this.colorDialog1.ShowDialog();
            // this.BackColor = this.colorDialog1.Color;
            String color = System.Drawing.ColorTranslator.ToHtml(this.colorDialog1.Color);
            baocunshezhiBJ(BJname, color);
            readshezhiBJ();
            listBJ();
        }

    }
}
